import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../res/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../res/style.dart';
import '../../../util/formatter/customized_length_formatter.dart';
import '../../../util/formatter/customized_text_formatter.dart';


class EditWidget extends StatefulWidget {
  ///输入框文字改变
  final ValueChanged<String>? onChanged;
  final List<TextInputFormatter>? inputFormatters;
  ///提示文字
  String hintText = "";
TextInputType textInputType;
  //左边标题
  String imgName;
  ///验证码
  bool codeType = false;
  bool isLogin;

  EditWidget({
    Key? key,
    this.onChanged,
    this.isLogin = true,
    this.hintText = "",
    this.codeType = false,
    this.inputFormatters,

    required this.imgName,
    this.textInputType = TextInputType.text,

  }) : super(key: key);

  @override
  State<EditWidget> createState() => _EditWidgetState();
}

class _EditWidgetState extends State<EditWidget> {

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: AlignmentDirectional.centerStart,
      children: [
        Container(
          // color: Colors.grey[400],
          margin:  EdgeInsets.only(top: 8, bottom: 8, left: 15, right:
          widget.codeType ? 85 : 15).r,
          // color: Colors.grey[400],
          child: TextField(
            keyboardType: widget.textInputType,
            textAlign: TextAlign.left,
            autofocus: false,
            maxLines: 1,
            style: Styles.style_black_16,
            onChanged: (text) {
              if (widget.onChanged != null) {
                widget.onChanged!(text);
              }
            },
            inputFormatters: widget.inputFormatters,

            ///样式
            decoration: InputDecoration(
                fillColor: Colors.white,
                filled: true,
                hintText: widget.hintText,
                hintStyle: Styles.style_placeholder,
                border: _getEditBorder(false),
                focusedBorder: _getEditBorder(true),
                disabledBorder: _getEditBorder(false),
                enabledBorder: _getEditBorder(false),
                contentPadding: const EdgeInsets.only(
                    top: 16, bottom: 16, left: 30, right: 16).r),
          ),
        ),
        Positioned(
          // width: 36.w,
          // height: 24.h,
          left: 5,
          child:Image.asset(widget.imgName,height: 25.h,width: 25.w,),
        ),


      ],
    );
  }

  ///获取输入框的Border属性，可公用
  ///[isEdit]是否获取焦点
  OutlineInputBorder _getEditBorder(bool isEdit) {
    return const OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(30)),
      borderSide: BorderSide(
        color:  Colors.white24,
        width: 1,
      ),
    );
  }
}
